namespace LikMS{

	class Probit{
		public:
		Probit(void){

			_d=new boost::math::normal_distribution<>(0,1);
		}
	double operator()(mat theta1, mat Xt, double *Y)
	{		
		double L=0;
		double sum=0;
		//Xb
		int n=Xt.n_rows;;
		mat foo(1,Xt.n_cols);
		for(int i=0;i<n;i++)
		{	
			foo= Xt.row(i);
			sum=dot(foo,theta1);
			if(Y[i]==1){
				L+=log(Phi(sum));
			}else{
				L+=log(1-Phi(sum));
			}	
		}
		//cout << exp(L);
		return L;

	}

	inline double Phi(double x)
	{
		double t=cdf((*_d),x);
	//	double t=0.5*(1+Erfm(x/sqrt(x)));
		if(t==1)
		{
			t=0.999999999;
		}
		if(t==0)
		{
			t=0.000000001;
		}
		return t;
	}
		private:	
	boost::math::normal_distribution<> *_d;

	};
	
	class Poisson{
		public:
		Poisson(void){

		}
	double operator()(mat theta1, mat X, double *Y)
	{
		mat theta=theta1.t();
		double L=0;
		double sum=0;
		//Xb
		int n=X.n_rows;
		for(int i=0;i<n;i++)
		{	
		//	cout << theta.col(0) << "\\";
			mat foo= X.row(i);
			sum=dot(foo,theta);
			L+=-exp(sum)+Y[i]*sum-logfact(Y[i]);
		}
		//cout << L+12200;
		return L;
	}


};


}

